package com.sk.govern.provideInter;

import com.alibaba.fastjson.JSON;
import com.sk.govern.client.CuratorClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/zookeeper")
public class TestZOOKeeper {

    @Autowired
    private CuratorClient curatorClient;

    @RequestMapping(value = "/createNode",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public String createNode(@RequestParam("path") String path, @RequestParam("value") String value){
        String nodeStr = null;
        try {
            nodeStr = curatorClient.createNode(path, value);
        }catch (Exception e){
            e.printStackTrace();
        }
        return nodeStr;
    }

    @RequestMapping(value = "/nodeData",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
    public String nodeData(@RequestParam("path") String path){
        String nodeStr = null;
        try {
            nodeStr = curatorClient.getNodeData(path);
        }catch (Exception e){
            e.printStackTrace();
        }
        return nodeStr;
    }
}
